$(function update_homework_list () {
    var strUrl = location.href;
    var arrUrl = strUrl.split("/");
    var strPage = arrUrl[arrUrl.length-1];
    var userinfo = {"userID": localStorage.getItem("userid"),
                    "html": strPage};
    var userInfo = JSON.stringify(userinfo);
    $.ajax({
        url: "/update_homework_manage",
        type: "POST",
        contentType: 'application/json; charset=UTF-8',
        data: userInfo,
        success: function (result) {
            switch (result.resultcode) {
                case '0':
                    window.alert("上传失败");
                    break;
                case '1':
                    document.write(result.html);
                    break;
                case '4001':
                    window.alert("登录学号不能为空");
                    break;
                case '4002':
                    window.alert("登录密码不能为空");
                    break;
                case '4003':
                    window.alert("注册学号不能为空");
                    break;
                case '4004':
                    window.alert("注册密码不能为空");
                    break;
                case '4005':
                    window.alert("注册邮箱不能为空");
                    break;
                case '4006':
                    window.alert("注册邮箱格式不正确");
                    break;
                case '4007':
                    window.alert("注册姓名不能为空");
                    break;
                case '4008':
                    window.alert("登录用户名或密码错误");
                    break;
                case '4009':
                    window.alert("用户注册尚未通过");
                    break;
                case '4010':
                    window.alert("没有需要审批的注册申请者");
                    break;
                case '4011':
                    window.alert("没有激活用户");
                    break;
                case '4012':
                    window.alert("待删除的用户没有userID");
                    break;
                default:
                    window.alert("系统错误");
            }
        },
        error: function () {
            window.alert("服务器错误");
        }
    });
});

function goto_checklist(obj) {
    localStorage.setItem("check_homeworkid", $(obj).val());
    window.location.href = "/homework_checklist";
}

function goto_update_homework(obj) {
    var homeworkinfo = {
        "userid": localStorage.getItem("userid"),
        "homeworkid": $(obj).val()
    };
    homeworkinfo = JSON.stringify(homeworkinfo);
    $.ajax({
        url: "/update_homework",
        type: "POST",
        contentType: 'application/json; charset=UTF-8',
        data: homeworkinfo,
        success: function (result) {
            switch (result.resultcode) {
                case '0':
                    window.alert("登录失败");
                    break;
                case '1':
                    document.write(result.html);
                    break;
                default:
                    window.alert("系统错误");
            }
        },
        error: function () {
            window.alert("连接失败");
        }
    })
}
function delete_homework(obj) {
    var homeworkid = $(obj).val();
    var homeworkinfo = {
        "userid": localStorage.getItem("userid"),
        "homeworkid": homeworkid
    };
    homeworkinfo = JSON.stringify(homeworkinfo);
    $.ajax({
        url: "/delete_homework",
        type: "POST",
        contentType: 'application/json; charset=UTF-8',
        data: homeworkinfo,
        success: function (result) {
            switch (result) {
                case '0':
                    window.alert("登录失败");
                    break;
                case '1':
                    location.reload(true);
                    break;
                default:
                    window.alert("系统错误");
            }
        },
        error: function () {
            window.alert("连接失败");
        }
    })
}
